//Documentation complete
/**
 * @author Kazu
 * @version 2009AP05
 */

package control;

import problemDomain.*;
import static problemDomain.ErrorBean.ErrorCode.*;
import broker.*;

import java.util.Date;
import java.util.List;

/**
 * Control object for cost vs. profit by menu item report.
 */
public class CostProfitByMenuItemReportControl extends Control {
	
	/* Attributes */
	
	private CostProfitByMenuItemReportBroker cpbmi;
	
	/* END Attributes */
	
	
	/* Constructors */
	
	
	/**
	 * Constructs a <code>CostProfitByMenuItemReportControl</code>.
	 * @throws ErrorBean if the database is not available
	 */
	public CostProfitByMenuItemReportControl () throws ErrorBean {
		cpbmi = CostProfitByMenuItemReportBroker.getBroker();
	}
	
	/* END Constructors */

	
	/* Methods */
	
	/**
	 * Generates the report.
	 * @param fromDate the date to lower bound the report
	 * @param toDate the date to upper bound the report
	 * @return a <code>List</code> of results
	 * @throws ErrorBean if the input data are not correct
	 */
	public List<MenuItemReport> getCostProfitByMIReport (String fromDate, String toDate) throws ErrorBean {
		return cpbmi.getReport(
			checkDate(fromDate),
			checkDate(toDate));
	}
	
	/* END Methods */
	
	
	/* Data Checks */
	
	private Date checkDate (String date) throws ErrorBean {
		return checkDate(date, REPORT_INVALID_DATE, this);}
	
	/* END Data Checks */
	
}
